﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class loadingpanel : MonoBehaviour
{
    public Text m_txtBaifenbi;
    public Image m_imgJindutiao;
    
    private float shujuleijia = 0;
    private float maxtime = 5;
    private bool jiazaizhong = false;
        
    // Start is called before the first frame update
    void Start()
    {
        m_txtBaifenbi.text = "0%";
        m_imgJindutiao.fillAmount = 0;
        
        shujuleijia = 0;
        maxtime = 5;
        jiazaizhong = true;
    }


    // Update is called once per frame
    void Update()
    {
        if (jiazaizhong)
        {
            shujuleijia += Time.deltaTime;
            m_txtBaifenbi.text = ((shujuleijia/maxtime)*100).ToString("f0")+"%";
            m_imgJindutiao.fillAmount = shujuleijia / maxtime;
            if (shujuleijia >= maxtime)
            {
                shujuleijia = 0;
                jiazaizhong = false;
                OnLoadEnd();
            }
        }
    }

    void OnLoadEnd()
    {
        Debug.Log("load end enter lobby");
        
        EventCenter.BroadCast(EventType.On_OPEN_PANEL,(object)2);
        this.gameObject.SetActive(false);
    }
}
